<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('产品上传统计')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								<label>产品名称：</label>
								<input type="text" name="productName" id="productName"/>
							</li>
							<li>
								<label>单位：</label>
								<input type="text" name="deptName" id="deptName"/>
							</li>
							<li class="select-time">
								<label>时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.table.exportExcelTwo()" shiro:hasPermission="statistics:uploading:export-particulars">
									<i class="fa fa-download"></i> 导出详情
								</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="statistics:uploading:export-statistics">
					<i class="fa fa-download"></i> 导出统计
				</a>-->
				<a class="btn btn-warning" onclick="dcnb()" shiro:hasPermission="statistics:uploading:export-statistics">
					<i class="fa fa-download"></i> 导出年报
				</a>
	        </div>

	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('statistics:uploading:view-particulars')}]];
		var prefix = ctx + "statistics";
		$('#startTime').val(getPreviousDay())
		$('#endTime').val(getNextDay())
		$(function() {
            var options = {
                url: prefix + "/selectUploadingStatisticsList",
				detailUrl: prefix + "/viewParticulars/{id}/"+$("#startTime").val()+"/"+$("#endTime").val(),
                exportUrl: prefix + "/exportStatistics",
                exportUrlTwo: prefix + "/exportParticulars",
                modalName: "上传统计",
                columns: [
				{
					field: 'productName',
					title: '产品名称',
					sortable: true
				},
				{
					field: 'normalUpload',
					title: '正常上传',
					sortable: true
				},
				{
					field: 'leakUpload',
					title: '异常',
					sortable: true
				},
				{
					field: 'lateUpload',
					title: '晚传',
					sortable: true
				},
			/*	{
					field: 'repairUpload',
					title: '补传',
					sortable: true
				},*/
				{
					field: 'shouldUpload',
					title: '应到',
					formatter: function(value, row, index) {
						if($("#startTime").val() != '' && $("#endTime").val() != ''){
							var d = dateDifferenceInDays($("#startTime").val(),$("#endTime").val())
							if(value == '03'){
								return (d*2)
							}
							return d;
						}else{
							var d = dateDifferenceInDays("2024-12-10",getCurrentDateString())
							if(value == '03'){
								return (d*2)
							}
							return d;
						}
					}
				},
				{
					field: 'realityUpload',
					title: '实到'
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="xq(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
						return actions.join('');

					}
				}]
            };
            $.table.init(options);
		});
		function xq(id){
			$.modal.open("详情",prefix + "/viewParticulars/"+id+"/"+$("#startTime").val()+"/"+$("#endTime").val(),1300,700);
		}

		//两个时间中间差几天
		function dateDifferenceInDays(date1Str, date2Str) {
			// 假设输入的日期字符串格式为 "yyyy-mm-dd"
			const date1 = new Date(date1Str);
			const date2 = new Date(date2Str);

			// 验证日期是否有效
			if (isNaN(date1.getTime()) || isNaN(date2.getTime())) {
				throw new Error('Invalid date format');
			}

			// 计算两个日期之间的毫秒数差异
			const differenceInMilliseconds = date2 - date1;

			// 将毫秒数转换为天数（1天 = 24小时 = 24 * 60分钟 = 24 * 60 * 60秒 = 24 * 60 * 60 * 1000毫秒）
			const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24);

			// 返回相差的天数，取整数部分
			return Math.abs(Math.round(differenceInDays));
		}

		/**
		 * 获取当前日期
		 * @returns {string}
		 */
		function getCurrentDateString() {
			// 创建一个新的Date对象，它会自动设置为当前日期和时间
			const now = new Date();

			// 获取年份、月份和日期
			const year = now.getFullYear();
			// 月份是从0开始的，所以需要加1，并且使用padStart确保是两位数
			const month = String(now.getMonth() + 1).padStart(2, '0');
			// 使用padStart确保日期是两位数
			const day = String(now.getDate()).padStart(2, '0');

			// 将它们组合成一个字符串，并返回
			return `${year}-${month}-${day}`;
		}

		//前一天时间
		function getPreviousDay() {
			const today = new Date(); // 获取当前时间
			const previousDay = new Date(today); // 复制当前时间对象
			previousDay.setDate(today.getDate()); // 将日期减少一天
			return formatDate(previousDay);
		}
		//后一天时间
		function getNextDay() {
			const today = new Date(); // 获取当前时间
			const nextDay = new Date(today); // 复制当前时间对象
			nextDay.setDate(today.getDate() + 1); // 将日期增加一天
			return formatDate(nextDay);
		}
		//时间格式转换
		function formatDate(date) {
			const year = date.getFullYear();
			const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并且补零
			const day = String(date.getDate()).padStart(2, '0'); // 日期可能是一位数，需要补零
			return `${year}-${month}-${day}`;
		}

		/**
		 * 导出年报
		 */
		function dcnb(){
			window.location.href = prefix + "/download-modified-word";
		}
	</script>
</body>
</html>
